package com.xiaodou.mjf.web.xface.product.controller;

import java.util.Map;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.google.common.collect.Lists;
import com.xiaodou.mjf.infrastructure.common.controller.ApiController;
import com.xiaodou.mjf.web.xface.common.API;
import com.xiaodou.mjf.web.xface.product.domain.MeiLiStageProduct;
import com.xiaodou.mjf.web.xface.product.domain.MeiLiStageProductDetail;
import com.xiaodou.mjf.web.xface.product.domain.Stage;

/**
 * Created by David on 2/3/15.
 */
@RestController
@RequestMapping("v1/product/staging")
public class MeiLiStageProductController extends ApiController {

	/*
	 * 产品模块 module 项目编号 category_item_id 省份编号 province_id 城市编号 city_id 机构编号
	 * organization_id 产品列表起始位置 start 分页显示行数 row
	 */
	@RequestMapping("")
	public Map<String, Object> list(
			String module,
			@RequestParam(value = "category_item_id", required = false) String category,
			@RequestParam(value = "province_id", required = false) String province,
			@RequestParam(value = "city_id", required = false) String city,
			@RequestParam(value = "organization_id", required = false) String organization,
			Integer start, Integer row) {

		if (start == null || start < 0) {
			start = 0;
		}

		if (row == null) {
			row = 20;
		}

		String imageServer = API.getImageServer();

		Map<String,Object> result = success();
		result.put("items", Lists.newArrayList(new MeiLiStageProduct("1",
				imageServer + "/files/product/icon/1.png", "美丽一号", 10000.0D,
				"1/3", "名称一"), new MeiLiStageProduct("2", imageServer
				+ "/files/product/icon/1.png", "美丽二号", 10000.0D, "1/3", "名称二"),
				new MeiLiStageProduct("3", imageServer
						+ "/files/product/icon/1.png", "美丽三号", 10000.0D, "1/3",
						"名称三"), new MeiLiStageProduct("4", imageServer
						+ "/files/product/icon/1.png", "美丽三号", 10000.0D, "1/3",
						"名称四"), new MeiLiStageProduct("5", imageServer
						+ "/files/product/icon/1.png", "美丽五号", 10000.0D, "1/3",
						"名称五"), new MeiLiStageProduct("6", imageServer
						+ "/files/product/icon/1.png", "美丽六号", 10000.0D, "1/3",
						"名称六")

		));

		return result;
	}

	@RequestMapping("{id}")
	public Map<String, Object> get(@PathVariable String id) {	

		MeiLiStageProductDetail stageProduct = new MeiLiStageProductDetail();
		stageProduct.setId("1");
		stageProduct.setName("投资10万松自体脂肪全面部填充");
		stageProduct.setAmount(100000D);
		stageProduct.setDownPayment("1/3");
		stageProduct.setOrganizationName("机构名称");
		stageProduct.setOrganizationDescription("机构信息");
		stageProduct.setInstallmentsAmount("3000");
		stageProduct.setAgeementTitle("产品购买协议名称");
		stageProduct.setAgreementUrl("http://www.baidu.com");
		stageProduct.setPaymentAgreementTitle("支付协议名称");
		stageProduct.setPaymentAgreementUrl("http://www.google.com");
		stageProduct.setStages(Lists.newArrayList(
                new Stage("6","4000"),
                new Stage("12","2000"),
                new Stage("24","1000")
        ));
		Map<String,Object> result = success();

		result.put("id", stageProduct.getId());
		result.put("name", stageProduct.getName());
		result.put("amount", stageProduct.getAmount());
		result.put("organization_name", stageProduct.getOrganizationName());
		result.put("down_payment", stageProduct.getDownPayment());
		result.put("organization_description", stageProduct.getOrganizationDescription());
		result.put("installments_amount", stageProduct.getInstallmentsAmount());
		result.put("ageement_title", stageProduct.getAgeementTitle());
		result.put("agreement_url", stageProduct.getAgreementUrl());
		result.put("payment_agreement_title", stageProduct.getPaymentAgreementTitle());
		result.put("stages", stageProduct.getStages());
		result.put("payment_agreement_url", stageProduct.getPaymentAgreementUrl());

		return result;
	}

}
